package cn.iocoder.yudao.module.cfs.service.company;

import cn.iocoder.yudao.module.cfs.controller.admin.company.vo.SysCompanyPageReqVO;
import cn.iocoder.yudao.module.cfs.controller.admin.company.vo.SysCompanySaveReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import cn.iocoder.yudao.module.cfs.dal.dataobject.company.SysCompanyDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.cfs.dal.mysql.company.SysCompanyMapper;

/**
 * sys_company Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class SysCompanyServiceImpl implements SysCompanyService {

    @Resource
    private SysCompanyMapper sysCompanyMapper;

    @Override
    public Long createSysCompany(SysCompanySaveReqVO createReqVO) {
        // 插入
        SysCompanyDO sysCompany = BeanUtils.toBean(createReqVO, SysCompanyDO.class);
        sysCompanyMapper.insert(sysCompany);

        // 返回
        return sysCompany.getCompanyCode();
    }

    @Override
    public void updateSysCompany(SysCompanySaveReqVO updateReqVO) {
        // 校验存在
        validateSysCompanyExists(updateReqVO.getCompanyCode());
        // 更新
        SysCompanyDO updateObj = BeanUtils.toBean(updateReqVO, SysCompanyDO.class);
        sysCompanyMapper.updateById(updateObj);
    }

    @Override
    public void deleteSysCompany(Long id) {
        // 校验存在
        validateSysCompanyExists(id);
        // 删除
        sysCompanyMapper.deleteById(id);
    }

    @Override
        public void deleteSysCompanyListByIds(List<Long> ids) {
        // 删除
        sysCompanyMapper.deleteByIds(ids);
        }


    private void validateSysCompanyExists(Long id) {
        if (sysCompanyMapper.selectById(id) == null) {
        }
    }

    @Override
    public SysCompanyDO getSysCompany(Long id) {
        return sysCompanyMapper.selectById(id);
    }

    @Override
    public PageResult<SysCompanyDO> getSysCompanyPage(SysCompanyPageReqVO pageReqVO) {
        return sysCompanyMapper.selectPage(pageReqVO);
    }

}